// settings.js
Page({
  data: {
    gameTime: 60, // 默认60秒
    wordCategory: '普通词汇',
    difficulty: '中等',
    // 时间选项
    timeOptions: [
      { value: 30, name: '30秒' },
      { value: 60, name: '60秒' },
      { value: 90, name: '90秒' },
      { value: 120, name: '120秒' }
    ],
    // 词库选项
    categoryOptions: [
      { value: '普通词汇', name: '普通词汇' },
      { value: '电影', name: '电影' },
      { value: '明星', name: '明星' },
      { value: '成语', name: '成语' }
    ],
    // 难度选项
    difficultyOptions: [
      { value: '简单', name: '简单' },
      { value: '中等', name: '中等' },
      { value: '困难', name: '困难' }
    ]
  },

  onLoad() {
    // 从本地存储读取游戏设置
    try {
      const gameOptions = wx.getStorageSync('gameOptions')
      if (gameOptions) {
        this.setData({
          gameTime: gameOptions.gameTime,
          wordCategory: gameOptions.wordCategory,
          difficulty: gameOptions.difficulty
        })
      }
    } catch (e) {
      console.error('读取设置失败', e)
    }
  },

  // 选择游戏时长
  selectTime(e) {
    const selectedTime = parseInt(e.currentTarget.dataset.value)
    this.setData({
      gameTime: selectedTime
    })
  },

  // 选择词库
  selectCategory(e) {
    const selectedCategory = e.currentTarget.dataset.value
    this.setData({
      wordCategory: selectedCategory
    })
  },

  // 选择难度
  selectDifficulty(e) {
    const selectedDifficulty = e.currentTarget.dataset.value
    this.setData({
      difficulty: selectedDifficulty
    })
  },

  // 返回上一页
  goBack() {
    wx.navigateBack()
  },

  // 开始游戏
  startGame() {
    // 保存设置到本地存储
    try {
      wx.setStorageSync('gameOptions', {
        gameTime: this.data.gameTime,
        wordCategory: this.data.wordCategory,
        difficulty: this.data.difficulty
      })
    } catch (e) {
      console.error('保存设置失败', e)
    }

    // 跳转到游戏页面
    wx.navigateTo({
      url: `/pages/game/game?time=${this.data.gameTime}&category=${this.data.wordCategory}&difficulty=${this.data.difficulty}`
    })
  }
}) 